<template>
	<view class="main">
		<uni-nav-bar @clickLeft="back" left-icon="left" title="委托下单" background-color="#007AFF" color="#000" statusBar="true"></uni-nav-bar>

		<scroll-view class="scrollView" scroll-y="true" @scrolltolower="handleScrolltolowerone()"
			:style="{height: setcollapseheight() + 'px'}" v-if="postList.length">
	<!-- 		<uni-segmented-control :current="current" :values="currentItems" styleType="text"
				@clickItem="onClickItem" />
			<view class="search-box">
				<view class="search-item">
					<view class="oneitem">
						<hpy-form-select style="width: 90%;" :dataList="batchList" text="batchName" name="batchId"
							v-model="searchForm.batchId" @change="batchChange" hideBorder title="选择服务项目" />
					</view>
				</view>
				<view class="search-item">
					<view class="twoitem">
						<uni-easyinput :inputBorder="false" trim="all" v-model="searchForm.vcostobjcode"
							placeholder="输入订单号检索" @change="changevcostobjcode"></uni-easyinput>
					</view>
					<button class="searchbutton" @click="reset()">
						<text>重置</text>
					</button>
				</view>
			</view> -->
			<entrustedItem :dataList="dataList"></entrustedItem>
		</scroll-view>



		<!-- <bottomBar ref="bottomBar"></bottomBar> -->
	</view>
</template>

<script>
	// import bottomBar from "@/components/socialized-bottomtabar/home-bottomtabar"
	import API from '@/api/socialized-servce/index-message/index.js'
	import entrustedItem from "./components/entrusted-item.vue"
	export default {
		components: {
			// bottomBar,
			entrustedItem
		},
		data() {
			return {
				current: 0,
				currentItems: ['全部', '进行中', '已结束'],
				page: 1,
				size: 10,
				total: 0,
				totalPages: 0,
				loading: false,
				postList: [],
				dataList: [1, 23, 4],
				searchForm: {},
				batchList: [],
			}
		},
		mounted() {
			this.setcollapseheight()
			this.getWaitPostList()
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},
			batchChange(e) {
				console.log(e);
			},
			//重置
			reset() {
				this.params = {}
				this.page = 1
				this.getWaitPostList()
			},
			async getWaitPostList() {
				if (this.loading) return
				this.loading = true
				let params = {
					page: this.page,
					size: this.size
				}
				let res = await API.getWaitPostList(params)
				if (res.code === 200) {
					this.total = res.data.totalElements
					this.totalPages = res.data.totalPages
					let newList = res.data.content
					if (this.page === 1) {
						this.postList = newList
					} else {
						this.postList = [...this.postList, ...newList]
					}
					// this.postList.forEach(el=>{
					// 	if(el.brief !== null) {
					// 		el.brief = el.brief.split(';')
					// 	}
					// })
					this.loading = false
				}
			},
			back() {
				uni.navigateBack({
					delta: 1
				});
			},
			setcollapseheight() {
				let topheightone = uni.upx2px(36)
				let winHeight = 0
				uni.getSystemInfo({
					success: function(res) {
						winHeight = res.windowHeight
					}
				});
				let oldHeight = uni.upx2px(56)

				winHeight = parseInt(winHeight) - topheightone - oldHeight
				// #ifndef H5
				winHeight = winHeight - 20

				// #endif
				return winHeight
			},
			handleScrolltolowerone() {
				if (this.loading) return;
				console.log('触底', this.page, this.totalPages);
				if (this.page <= this.totalPages && this.page * 10 < this.total) {
					this.page++
					this.getWaitPostList()
				}
			},
		}

	}
</script>

<style lang="scss" scoped>
	.scrollView {
		// padding-top: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;

		.content {
			width: 100%;
			color: #000;

			.item {
				position: relative;
				padding: 0 40rpx;
				font-size: 28rpx;
				margin-bottom: 20rpx;

				.dot {
					position: absolute;
					top: 60rpx;
					right: 52rpx;
					width: 16rpx;
					height: 16rpx;
					border-radius: 50%;
					background-color: red;
					z-index: 999;
				}

				.img {
					position: absolute;
					top: 66rpx;
					right: 60rpx;
					width: 34rpx;
				}

				.title {
					padding-bottom: 10rpx;
					border-bottom: 2rpx solid #c7c7c9;
					color: #91743E;
				}

				.brief {
					.brief-item {
						width: 100%;
					}
				}

				.sendTime {
					width: 100%;
					text-align: center;
					margin-bottom: 10rpx;
					color: #c7c7c9;
				}

				.container {
					padding: 22rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.05);
					border-radius: 10rpx 10rpx 10rpx 10rpx;

					.title {
						display: flex;
						font-weight: 700;
						overflow: hidden;
						font-size: 32rpx;
					}

					.brief {
						margin-top: 20rpx;
					}

					.times {
						margin-top: 26rpx;
						font-size: 28rpx;
						color: #606060;
					}
				}
			}

		}
	}

	.noData {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translateX(-50%) translateY(-50%);
		width: 100%;

		.img {
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				width: 166rpx;
				height: 153rpx;
			}

			.tex {
				font-size: 32rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #525252;
			}
		}

	}

	.search-box {
		margin-top: 28rpx;
		// display: flex;
		// justify-content: space-around;
		// align-items: center;

		.search-item {
			margin: 0rpx auto;
			padding-top: 10rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			// box-sizing: border-box;

			.oneitem {
				width: 680rpx;
				height: 80rpx;
				opacity: 1;
				border-radius: 40rpx;
				background: rgba(255, 255, 255, 1);
				box-shadow: 0rpx 6rpx 12rpx rgba(0, 0, 0, 0.18);
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 0rpx 20rpx;
				box-sizing: border-box;
				margin: 0rpx auto;
			}

			.twoitem {
				margin: 0rpx auto;
				width: 540rpx;
				height: 80rpx;
				opacity: 1;
				border-radius: 40rpx;
				background: rgba(255, 255, 255, 1);
				box-shadow: 0rpx 6rpx 12rpx rgba(0, 0, 0, 0.18);
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 0rpx 20rpx;
				box-sizing: border-box;
			}
		}

		.searchbutton {
			font-size: 28rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 64rpx;
			width: 120rpx;
			height: 58rpx;
			opacity: 1;
			border-radius: 30rpx;
			background: linear-gradient(270deg, rgba(136, 172, 255, 1) 0%, rgba(33, 101, 255, 1) 100%);


		}
	}
</style>